package org.apache.flink.runtime.allocatedeploy;

import java.util.List;
import java.util.function.BiConsumer;

import org.apache.flink.runtime.allocatedeploy.execution.Execution;
import org.apache.flink.runtime.allocatedeploy.execution.ExecutionID;
import org.apache.flink.runtime.clusterframework.types.AllocationID;
import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
import org.slf4j.Logger;

/**
 * @类名: ExecutionDeployer
 * @说明: 执行部署器，负责申请资源，部署执行
 *
 * @author   leehom
 * @Date	 2024年7月29日 下午4:58:19
 * 修改记录：
 *
 * @see 	 
 */
public interface ExecutionDeployer {

    /**
     * 分配资源slot，部署指向性
     *
     * @param executionsToDeploy executions to deploy
     * @param requiredVersionByVertex required versions of the execution vertices. If the actual
     *     version does not match, the deployment of the execution will be rejected.
     */
    void allocateSlotsAndDeploy(
            final List<Execution> executionsToDeploy);

    /** Factory to instantiate the {@link ExecutionDeployer}. */
    interface Factory {

        /**
         * Instantiate an {@link ExecutionDeployer} with the given params. Note that the version of
         * an execution vertex will be recorded before scheduling executions for it. The version may
         * change if a global failure happens, or if the job is canceled, or if the execution vertex
         * is restarted when all its current execution are FAILED/CANCELED. Once the version is
         * changed, the previously triggered execution deployment will be skipped.
         *
         * @param log the logger
         * @param executionSlotAllocator the allocator to allocate slots
         * @param executionOperations the operations of executions
         * @param allocationReservationFunc function to reserve allocations for local recovery
         * @param mainThreadExecutor the main thread executor
         * @return an instantiated {@link ExecutionDeployer}
         */
        ExecutionDeployer createInstance(
                final Logger log,
                final ExecutionSlotAllocator executionSlotAllocator, // 分配器
                final ExecutionOperations executionOperations, // 执行操作
                final BiConsumer<ExecutionID, AllocationID> allocationReservationFunc, // 调度器适用
                final ComponentMainThreadExecutor mainThreadExecutor); //
    }
}
